﻿using MediatR;
using MS.Data.API.Write.Applicant.Command;
using MS.Data.API.Write.Applicant.Command.User;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Write.Applicant.CommandHandel.User
{

    public class DelUserCommandHandel : IRequestHandler<DelUserCommand, APIResult<int>>
    {
        /// <summary>
        /// 用户
        /// </summary>
        IBaseRepository<Domain.User> perRep;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="perRep">用户</param>
        public DelUserCommandHandel(IBaseRepository<Domain.User> perRep)
        {
            this.perRep = perRep;
        }
        /// <summary>
        ///  处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回权限列表结果</returns>
        public async Task<APIResult<int>> Handle(DelUserCommand request, CancellationToken cancellationToken)
        {
            var list = await perRep.Bysty(request.UserId);
            list.IsDel = true;

            await perRep.Update(list);

            return new APIResult<int>()
            {
                code = APIEnum.删除成功,
                data = 1,
                mes = ""
            };

        }

    }
}
